home *** CD-ROM | disk | FTP | other *** search
-
- /* Copyright 1986 Eric Jul. May not be used for any purpose without */
- /* written permission from the author. */
- /* The Emerald kernel for the Emerald programming language. */
-
- /* This file contains the implementation of the Emerald item handler */
-
- #include "Kernel/h/assert.h"
- #include "Kernel/h/system.h"
- #include "Kernel/h/errMsgs.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/kmdTypes.h"
- #include "Kernel/h/emCodes.h"
- #include "Kernel/h/mmMsgTypes.h"
- #include "Kernel/h/lmTypes.h"
- #include "Kernel/h/emkDefs.h"
- #include "Kernel/h/lmCodes.h"
- #include "Kernel/h/utils.h"
-
- ItemHandlerPtr handlers[MAXTAG];
- static int initialized = 0;
-
- /**********************************************************************/
- /* Item Handler */
- /**********************************************************************/
-
- HResult ItemHandler(fHandle)
- LMHandle fHandle;
- {
- ItemHdr hdr;
- int length;
- register ItemHandlerPtr theItemHandler;
-
- KMDTrace("Item", 3, "ItemHandler from LNN %d\n",
- fHandle->mmMsgHdr.MsgSrc);
- for (;;) {
- length = sizeof(hdr);
- LMGetData(&fHandle, &hdr, &length);
- if (length == 0) {
- break;
- }
- if (length < sizeof(hdr)) {
- ErrMsg("Bad Item in Long Msg\n");
- break;
- }
- assert ( (int) hdr.itemTag < MAXTAG);
- KMDTrace("Item", 3, "Item: ITag %s, size %d\n", PPITag(hdr.itemTag),
- hdr.size);
- theItemHandler = handlers[(int) hdr.itemTag];
- assert(NonNULL(theItemHandler));
- KMDTrace("Item", 5, "Invoking handler no. %d at addr 0x%05x\n",
- hdr.itemTag, theItemHandler);
- (*theItemHandler)(&fHandle, hdr);
- }
- LMClose(&fHandle);
- }
-
- /**********************************************************************/
- /* SetItemHandler */
- /**********************************************************************/
-
- void SetItemHandler(fTag, fHandler)
- ITag fTag;
- ItemHandlerPtr fHandler;
- {
- register int i;
- KMDTrace("Item", 5, "SetItemHandler[%d] to addr 0x%05x, ITag %s\n", fTag,
- fHandler, PPITag(fTag));
- assert( (unsigned int) fTag < MAXTAG);
- if (!initialized) {
- initialized = 1;
- for (i = 0; i < MAXTAG; i++) handlers[i] = (ItemHandlerPtr) NULL;
- }
- handlers[(unsigned int) fTag] = fHandler;
- }
- /**********************************************************************/
- /* Item initialization */
- /**********************************************************************/
-
- void ItemInit()
- {
- KMDSetTrace(Item);
- KMDTrace("Item", 5, "ItemInit, sizeof(ItemHdr) is %d bytes, MAXTAG %d\n",
- sizeof(ItemHdr), MAXTAG);
- MMDefineMsgHandler(KMSG_EmKernel, EMKM_Item, (HandlerPtr)ItemHandler,
- (HandlerPtr *)NULL);
- }
-
- /**********************************************************************/
-
- /* Copyright 1986 Eric Jul */
-